const app = getApp()
Page({
  data: {
    statusBar: app.globalData.statusBar,
    customBar: app.globalData.customBar,
    custom: app.globalData.custom,
    // 首页轮播数据
    swiperData: [
      {
        id: 0,
        image_src: 'https://www.zjteam.com/zjteam_test/wzk/image/buaner1.png',
      },
      {
        id: 1,
        image_src: 'https://www.zjteam.com/zjteam_test/wzk/image/buaner1.png',
      },
      {
        id: 2,
        image_src: 'https://www.zjteam.com/zjteam_test/wzk/image/buaner1.png',
      },
      {
        id: 3,
        image_src: 'https://www.zjteam.com/zjteam_test/wzk/image/buaner1.png',
      },
    ],
    // 轮播图选中id
    curIndex: 0,
    autoplayFlag: false,
    // 解决抖动问题
    currentDot: 0,
  },
  onLoad() {
    //创建节点选择器
    const that = this
    let swiper = wx.createSelectorQuery()
    swiper.select('#swiper').boundingClientRect()
    swiper.exec(function (res) {
      //res就是 所有标签为mjltest的元素的信息 的数组
      that.setData({
        swiperH: res[0].height,
      })
    })
  },
  onShow() {
    this.setData({
      autoplayFlag: true,
    })
  },
  onHide() {
    this.setData({
      autoplayFlag: false,
    })
  },
  _toTest() {
    wx.navigateTo({
      url: '/pages/item/item',
    })
  },
  // 跳转课程页
  _toCoures() {
    wx.switchTab({
      url: '/pages/course/course',
    })
  },
  // 轮播图
  _swiperChange(e) {
    this.setData({
      curIndex: e.detail.current,
    })
  },
  // 轮播小圆点
  _dotChange(e) {
    this.setData({
      currentDot: e.detail.current,
    })
  },
  // 获取滚动条当前位置
  onPageScroll: function (e) {
    let that = this

    let scrollH = that.data.swiperH

    if (e.scrollTop <= scrollH) {
      this.setData({
        scrollRate: e.scrollTop / scrollH,
      })
    } else {
      this.setData({
        scrollRate: 1,
      })
    }
  },
})
